package com.rest.demo.config.properties;

import com.zaxxer.hikari.HikariDataSource;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

/**
 * @author Administrator
 * @decription hikariCP 数据库连接池配置
 * @Date 2018-02-06 14:03
 */
@Component
@ConfigurationProperties(prefix = "spring.datasource")
public class HikariProperties {

    private String url = "jdbc:mysql://127.0.0.1:3306/demo?autoReconnect=true&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false";

    private String username = "root";

    private String password = "root";

    private String driverClassName = "com.mysql.jdbc.Driver";

    private boolean readOnly = false;

    private long timeOut = 30000;

    private long idleTimeOut = 600000;

    private long maxLifetime = 1800000;

    private int maxPoolsize = 20;

    public void config(HikariDataSource dataSource) {
        dataSource.setJdbcUrl(url);
        dataSource.setUsername(username);
        dataSource.setPassword(password);

        dataSource.setReadOnly(readOnly);
        dataSource.setConnectionTimeout(timeOut);
        dataSource.setIdleTimeout(idleTimeOut);
        dataSource.setMaxLifetime(maxLifetime);
        dataSource.setMaximumPoolSize(maxPoolsize);
        dataSource.setDriverClassName(driverClassName);
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getDriverClassName() {
        return driverClassName;
    }

    public void setDriverClassName(String driverClassName) {
        this.driverClassName = driverClassName;
    }

    public boolean isReadOnly() {
        return readOnly;
    }

    public void setReadOnly(boolean readOnly) {
        this.readOnly = readOnly;
    }

    public long getTimeOut() {
        return timeOut;
    }

    public void setTimeOut(long timeOut) {
        this.timeOut = timeOut;
    }

    public long getIdleTimeOut() {
        return idleTimeOut;
    }

    public void setIdleTimeOut(long idleTimeOut) {
        this.idleTimeOut = idleTimeOut;
    }

    public long getMaxLifetime() {
        return maxLifetime;
    }

    public void setMaxLifetime(long maxLifetime) {
        this.maxLifetime = maxLifetime;
    }

    public int getMaxPoolsize() {
        return maxPoolsize;
    }

    public void setMaxPoolsize(int maxPoolsize) {
        this.maxPoolsize = maxPoolsize;
    }
}
